package com.cet.algorithm.数组;

/**
 * @program: cet-practice
 * @description: 长度最小的子数组
 * @author: 陈恩涛
 * @create: 2023-05-05 10:28
 **/
public class LC209 {

    public static void main(String[] args) {

    }

    // 滑动窗口
    public static  int minSubArrayLen(int s, int[] nums) {
        int left = 0;
        int sum = 0;
        int result = Integer.MAX_VALUE;
        for (int right = 0; right < nums.length; right++) {
            sum += nums[right];
            while (sum >= s) {
                result = Math.min(result, right - left + 1);
                sum -= nums[left++];
            }
        }
        return result == Integer.MAX_VALUE ? 0 : result;
    }
}
